///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.data.vo {
	import flash.utils.describeType;
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;
	
	import sugarcookie.collections.EnhancedArrayCollection;
	import sugarcookie.data.vo.Common;
	import sugarcookie.data.vo.Meta;
	
	dynamic public class AppData extends Proxy {
		private var _id:String;
		private var _meta:Meta;
		private var _common:Common;
		private var _views:EnhancedArrayCollection;
		
		public function AppData() {
			_views = new EnhancedArrayCollection();
		}
		
		public function set id(s:String):void {
			_id = s;
		}
		
		public function get id():String {
			return _id;
		}
		
		public function set meta(m:Meta):void {
			_meta = m;
		}
		
		public function get meta():Meta {
			return _meta;
		}
		
		public function set common(c:Common):void {
			_common = c;
		}
		
		public function get common():Common {
			return _common;
		}
		
		public function get views():Array {
			return _views.source;	
		}
		
		override flash_proxy function setProperty(name:*, value:*):void {
			var str:String = XML(describeType(value)).@name;
			if (str.indexOf("View")!=-1) _views.addItemWithKey(name,value);
		}
		
		override flash_proxy function getProperty(name:*):* {
			if (_views.containsKey(name)) return _views.getItemAtKey(name);
	        
	        return null;
		}
	}
}